package com.hexacta.hrs.test.data;

import java.util.List;
import java.util.Map;

import org.vectrics.user.UserPrivilegeType;
import org.vectrics.user.UserPrivilegeTypeGroup;

/**
 * Test data dependency creator for the UserPrivilegeType class.
 * 
 * @author tpollak
 */
public class UserPrivilegeTypeTestDataDependencyCreator extends AbstractTestDataDependencyCreator {

    public static final String ACCESS_USER_PRIV_TYPE_GROUP = "ACCESS_USER_PRIV_TYPE_GROUP";

    public static final String COMPANY_USER_PRIV_TYPE_GROUP = "COMPANY_USER_PRIV_TYPE_GROUP";

    public static final String HTML_USER_PRIV_TYPE_GROUP = "HTML_USER_PRIV_TYPE_GROUP";

    public static final String JOB_USER_PRIV_TYPE_GROUP = "JOB_USER_PRIV_TYPE_GROUP";

    public static final String PERSON_USER_PRIV_TYPE_GROUP = "PERSON_USER_PRIV_TYPE_GROUP";

    public static final String RESUME_USER_PRIV_TYPE_GROUP = "RESUME_USER_PRIV_TYPE_GROUP";

    public static final String ROLE_ASSIGN_USER_PRIV_TYPE_GROUP = "ROLE_ASSIGN_USER_PRIV_TYPE_GROUP";

    public static final String SECURITY_USER_PRIV_TYPE_GROUP = "SECURITY_USER_PRIV_TYPE_GROUP";

    public static final String SYSTEM_USER_PRIV_TYPE_GROUP = "SYSTEM_USER_PRIV_TYPE_GROUP";

    public UserPrivilegeTypeTestDataDependencyCreator(List<TestDataDependencyCreator> dependencies) {
        super(dependencies);
    }

    public void createDependentTestData(Map<String, Object> context) {
        // Create UserPrivilegeTypeGroups
        UserPrivilegeTypeGroup access = this.createUserPrivilegeTypeGroup(context, "access", "role.group.access");
        UserPrivilegeTypeGroup company = this.createUserPrivilegeTypeGroup(context, "company", "role.group.company");
        UserPrivilegeTypeGroup html = this.createUserPrivilegeTypeGroup(context, "html", "role.group.html");
        UserPrivilegeTypeGroup job = this.createUserPrivilegeTypeGroup(context, "job", "role.group.job");
        UserPrivilegeTypeGroup person = this.createUserPrivilegeTypeGroup(context, "person", "role.group.person");
        UserPrivilegeTypeGroup resume = this.createUserPrivilegeTypeGroup(context, "resume", "role.group.resume");
        UserPrivilegeTypeGroup roleAssign = this.createUserPrivilegeTypeGroup(context, "role.assign",
                "role.group.role.assign");
        UserPrivilegeTypeGroup security = this.createUserPrivilegeTypeGroup(context, "security", "role.group.security");
        UserPrivilegeTypeGroup system = this.createUserPrivilegeTypeGroup(context, "system", "role.group.system");

        access = this.insertCodedObject(access);
        company = this.insertCodedObject(company);
        html = this.insertCodedObject(html);
        job = this.insertCodedObject(job);
        person = this.insertCodedObject(person);
        resume = this.insertCodedObject(resume);
        roleAssign = this.insertCodedObject(roleAssign);
        security = this.insertCodedObject(security);
        system = this.insertCodedObject(system);

        // Create UserPrivilegeTypes
        this.createAndInsertUserPrivilegeType(context, "admin.access", access, "role.admin.access",
                "User can access administration pages.", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.admin.cmpy.grp", security,
                "role.assign.admin.comany.grp", "", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.admin.group", security, "role.assign.admin.group",
                "User can assign other users to administration group", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.admin.roles", security, "role.assign.admin.roles",
                "Administrative level ability to assign roles to other users", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.candidate.group", security,
                "role.assign.candidate.group", "User can assign users to candidate privilege group", true, false);
        this.createAndInsertUserPrivilegeType(context, "assign.contact.cmpy.grp", security,
                "role.assign.contact.comany.grp", "", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.hire.mgr.cmpy.grp", security,
                "role.assign.hire.mgr.comany.grp", "", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.hiring.mgr.group", security,
                "role.assign.hiring.mgr.group", "User can assign users to hiring manager group", true, false);
        this.createAndInsertUserPrivilegeType(context, "assign.recr.mgr.cmpy.grp", security,
                "role.assign.recr.mgr.comany.grp", "", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.recruit.admin.roles", security,
                "role.assign.recruit.admin.roles", "User can administer recruiting roles", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.recruit.cmpy.grp", security,
                "role.assign.recruit.comany.grp", "User can assign users to company recruiter group", true, true);
        this.createAndInsertUserPrivilegeType(context, "assign.recruit.group", security, "role.assign.recruit.group",
                "User can assign users to recruiter role", true, false);
        this.createAndInsertUserPrivilegeType(context, "assign.recruit.mgr.group", security,
                "role.assign.recruit.mgr.group", "User can assign user to recruiting manager privilege group", true,
                false);
        this.createAndInsertUserPrivilegeType(context, "assign.recruit.roles", security, "role.assign.recruit.roles",
                "User can assign recruiter roles", true, false);
        this.createAndInsertUserPrivilegeType(context, "assign.source.group", security, "role.assign.source.group",
                "User can assign users to source privilege group", true, false);
        this.createAndInsertUserPrivilegeType(context, "candidate.profile.access", access,
                "role.candidate.profile.access", "User can access user profile on public web site.", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.create", company, "role.company.add",
                "User can create new companies", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.create.notify", company, "role.company.create.notify",
                "User will be notified when a company is created.", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.edit", company, "role.company.edit",
                "User can modify company information", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.edit.notify", company, "role.company.edit.notify",
                "User will be notified when a company is modified", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.remove", company, "role.company.remove",
                "User can remove companies", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.remove.notify", company, "role.company.remove.notify",
                "User will be notified when a company is removed", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.view", company, "role.company.view",
                "User can view companies", true, true);
        this.createAndInsertUserPrivilegeType(context, "company.view.associates", company,
                "role.company.view.associates", "User can view employees of companies", true, true);
        this.createAndInsertUserPrivilegeType(context, "domain.access", access, "role.domain.global.access",
                "User can view domains data", true, true);
        this.createAndInsertUserPrivilegeType(context, "finance.admin", security, "role.user.finance.admin",
                "User is the finance and admin", true, true);
        this.createAndInsertUserPrivilegeType(context, "html.change", html, "role.html.change",
                "User can change the look and feel of the public web site.", true, true);
        this.createAndInsertUserPrivilegeType(context, "job.create", job, "role.job.create", "", true, true);
        this.createAndInsertUserPrivilegeType(context, "job.create.notify", job, "role.job.create.notify",
                "User will be notified when job orders are created", true, true);
        this.createAndInsertUserPrivilegeType(context, "job.edit", job, "role.job.edit", "User can edit job", true,
                true);
        this.createAndInsertUserPrivilegeType(context, "job.edit.notify", job, "role.job.edit.notify",
                "User will be notified when job orders are modified", true, true);
        this.createAndInsertUserPrivilegeType(context, "job.remove", job, "role.job.remove",
                "User can remove job orders", true, true);
        this.createAndInsertUserPrivilegeType(context, "job.select.candidates", job, "role.job.select.candidates",
                "User can select candidates to add to job orders", true, true);
        this.createAndInsertUserPrivilegeType(context, "job.status.change.notify", job,
                "role.job.status.change.notify", "User will be notified for status changes of job orders", true, true);
        this.createAndInsertUserPrivilegeType(context, "job.view", job, "role.job.view", "User can view job orders",
                true, true);
        this.createAndInsertUserPrivilegeType(context, "job.view.candidates", job, "role.job.view.candidates",
                "User can view job candidates", true, true);
        this.createAndInsertUserPrivilegeType(context, "location.approve", system, "role.location.approve", "", true,
                true);
        this.createAndInsertUserPrivilegeType(context, "notify.system.error", system, "role.notify.system.error", "",
                true, true);
        this.createAndInsertUserPrivilegeType(context, "person.create", person, "role.person.create",
                "User can create people", true, true);
        this.createAndInsertUserPrivilegeType(context, "person.edit", person, "role.person.edit",
                "User can modify person", true, true);
        this.createAndInsertUserPrivilegeType(context, "person.remove", person, "role.person.remove",
                "User can remove people from system", true, true);
        this.createAndInsertUserPrivilegeType(context, "person.view", person, "role.person.view",
                "User can view persons", true, true);
        this.createAndInsertUserPrivilegeType(context, "resume.batch.run", resume, "role.resume.batch.run",
                "User can run resume scans", true, true);
        this.createAndInsertUserPrivilegeType(context, "resume.batch.view", resume, "role.resume.batch.view",
                "User can view resume scans and results", true, true);
        this.createAndInsertUserPrivilegeType(context, "resume.view", resume, "role.resume.view",
                "User can view resumes", true, true);
        this.createAndInsertUserPrivilegeType(context, "user.password.edit", person, "role.user.password.edit",
                "User can modify other user passwords", true, true);
        this.createAndInsertUserPrivilegeType(context, "user.role.edit", person, "role.user.role.edit",
                "User can modify user information", true, true);

    }

    private UserPrivilegeType createAndInsertUserPrivilegeType(Map<String, Object> context, String code,
            UserPrivilegeTypeGroup group, String name, String description, boolean isCompanyRole, boolean isGlobalRole) {
        UserPrivilegeType user = this.createUserPrivilegeType(code, group, name, description, isCompanyRole,
                isGlobalRole);
        user = this.insertCodedObject(user);
        return user;
    }

    private UserPrivilegeType createUserPrivilegeType(String code, UserPrivilegeTypeGroup group, String name,
            String description, boolean isCompanyRole, boolean isGlobalRole) {
        UserPrivilegeType user = new UserPrivilegeType();
        user.setCode(code);
        user.setName(name);
        user.setDescription(description);
        user.setUserPrivilegeTypeGroup(group);
        user.setCompanyRole(isCompanyRole);
        user.setGlobalRole(isGlobalRole);
        user.setStartDate(this.getDataUtils().createCurrentDate());
        user.setEndDate(null);
        return user;
    }

    private UserPrivilegeTypeGroup createUserPrivilegeTypeGroup(Map<String, Object> context, String code,
            String descriptionCode) {
        UserPrivilegeTypeGroup user = new UserPrivilegeTypeGroup();
        user.setCode(code);
        user.setDescriptionCode(descriptionCode);

        return user;
    }
}
